Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

Given the following base C++ class, class area_cl { public: double height; double width; }; Create two derived classes called rectangle and isosceles that inherit area_cl. Have each class include a...

Given the following base C++ class,
class area_cl {
public:
double height;
double width;
};
Create two derived classes called rectangle and isosceles that inherit area_cl. Have each class include a function called area()
that returns the area of a rectangle or isosceles triangle, as appropriate. Use parameterized constructors to initialize height and width.

Answers


Davis
#include
using namespace std;
class area_cl {
public:
double height;
double width;
};
class rectangle : public area_cl {
public :
rectangle (double h, double w) ;
double area();
};
class isosceles : public area {
public:
isosceles (double h, double w);
double area();
};
rectangle ::rectangle(double h, double w)
{
height = h;
width = w;
}
isosceles ::isosceles (double h, double w)
{
height = h;
width = w;
}
double rectangle :: area()
{
return width *height;
}
double isosceles :: area()
{
return 0.5 * width * height;
}
int main()
{
rectangle b(10.0, 5.0);
isosceles i(4.0, 6.0);
cout << "Rectangle: " << b.area() << "\n";
cout << "Triangle: " << i.area() << "\n";
return 0;
}
Githiari answered the question on May 12, 2018 at 16:23

Answer Attachments

Exams With Marking Schemes

Related Questions